package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.EvaluationItems;
import com.ruoyi.system.service.IEvaluationItemsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 评分项配置Controller
 * 
 * @author ruoyi
 * @date 2025-05-12
 */
@Controller
@RequestMapping("/system/items")
public class EvaluationItemsController extends BaseController
{
    private String prefix = "system/items";

    @Autowired
    private IEvaluationItemsService evaluationItemsService;

    @RequiresPermissions("system:items:view")
    @GetMapping()
    public String items()
    {
        return prefix + "/items";
    }

    /**
     * 查询评分项配置列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EvaluationItems evaluationItems)
    {
        startPage();
        List<EvaluationItems> list = evaluationItemsService.selectEvaluationItemsList(evaluationItems);
        for (EvaluationItems evaluationItem : list) {
            evaluationItem.setScoreSet("");
            evaluationItem.setScoreYj("请输入意见");
        }
        return getDataTable(list);
    }

    /**
     * 导出评分项配置列表
     */
    @RequiresPermissions("system:items:export")
    @Log(title = "评分项配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EvaluationItems evaluationItems)
    {
        List<EvaluationItems> list = evaluationItemsService.selectEvaluationItemsList(evaluationItems);
        ExcelUtil<EvaluationItems> util = new ExcelUtil<EvaluationItems>(EvaluationItems.class);
        return util.exportExcel(list, "评分项配置数据");
    }

    /**
     * 新增评分项配置
     */
    @RequiresPermissions("system:items:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存评分项配置
     */
    @RequiresPermissions("system:items:add")
    @Log(title = "评分项配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EvaluationItems evaluationItems)
    {
        return toAjax(evaluationItemsService.insertEvaluationItems(evaluationItems));
    }

    /**
     * 修改评分项配置
     */
    @RequiresPermissions("system:items:edit")
    @GetMapping("/edit/{itemId}")
    public String edit(@PathVariable("itemId") Long itemId, ModelMap mmap)
    {
        EvaluationItems evaluationItems = evaluationItemsService.selectEvaluationItemsByItemId(itemId);
        mmap.put("evaluationItems", evaluationItems);
        return prefix + "/edit";
    }

    /**
     * 修改保存评分项配置
     */
    @RequiresPermissions("system:items:edit")
    @Log(title = "评分项配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EvaluationItems evaluationItems)
    {
        return toAjax(evaluationItemsService.updateEvaluationItems(evaluationItems));
    }

    /**
     * 删除评分项配置
     */
    @RequiresPermissions("system:items:remove")
    @Log(title = "评分项配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(evaluationItemsService.deleteEvaluationItemsByItemIds(ids));
    }
}
